﻿
//Author: 张亚涛
//createtime:2016-03-10 09:47:25
//Description: 

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using WechatUtility;

namespace BLL
{

    /// <summary>
    /// 该类提供了一系列操作 "Partner" 表的方法;
    /// </summary>
    public class PartnerService
    {
        #region .对本表的维护.
        #region select data
        /// <summary>
        /// 返回Partner表的所有数据  
        /// </summary>
        /// <returns></returns>        
        public static List<Partner> GetAllPartner()
        {
            return PartnerBase.GetAllPartner();
        }
        /// <summary>
        /// 根据Partner表的ID字段返回数据  
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>        
        public static Partner GetPartnerById(int id)
        {
            return PartnerBase.GetPartnerById(id);
        }
        /// <summary>
        /// 判断推广码是否已存在
        /// </summary>
        /// <param name="partnerNo">推广码</param>
        /// <returns>返回True或Flase;True表示存在，Flase表示不存在</returns>
        public static bool IsExistPartnerNo(string partnerNo)
        {
            return PartnerBase.IsExistPartnerNo(partnerNo);
        }
        /// <summary>
        /// 生成推广码
        /// </summary>
        /// <returns>推广码</returns>
        public static string CreatePartnerNo()
        {
            string partnerNo = Utilities.GetRandom(8);
            while (IsExistPartnerNo("S" + partnerNo))
            {
                partnerNo = Utilities.GetRandom(8);
            }

            return partnerNo;
        }
        /// <summary>
        /// 获得赠送体验券数量
        /// </summary>
        /// <param name="partnerNo">推广码</param>
        /// <returns></returns>
        public static int GetNum(string partnerNo)
        {
            return PartnerBase.GetNum(partnerNo);
        }
        #endregion
        #region delete data
        /// <summary>
        /// 根据Partner表的ID字段删除数据 
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>返回受影响的行数</returns>
        public static int DeletePartnerById(int id)
        {
            return PartnerBase.DeletePartnerById(id);
        }
        #endregion
        #region update data
        /// <summary>
        /// 根据Partner表的ID字段更新数据 
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="Partner">partner</param>
        /// <returns>返回受影响的行数</returns>
        public static int UpdatePartnerById(Partner partner)
        {
            return PartnerBase.UpdatePartnerById(partner);
        }
        #endregion
        #region insert data
        /// <summary>
        /// 向Partner表插入一条数据，插入成功则返回自增列数值，插入不成功则返回-1 
        /// </summary>
        /// <param name="partner">Partner</param>        
        /// <returns></returns>
        public static int AddPartner(Partner partner)
        {
            return PartnerBase.AddPartner(partner);
        }
        #endregion
        #endregion

        #region .SQL语句汇总.
        /// <summary>
        /// 返回Partner表的所有数据（SQL语句） 
        /// </summary>
        /// <returns></returns>        
        public static string GetAllPartner_SQL()
        {
            return PartnerBase.GetAllPartner_SQL();
        }
        /// <summary>
        /// 获得推广用户统计（SQL语句）
        /// </summary>
        /// <param name="partnerNo">推广码</param>
        /// <param name="month">月份</param>
        /// <returns></returns>
        public static string GetStic_SQL(string partnerNo, string month)
        {
            return PartnerBase.GetStic_SQL(partnerNo, month);
        }
        #endregion
    }
}